/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package caintra.Sapra.ComponentsImplements;

import caintra.Sapra.Model.Calendariofacturacionpracticantes;
import caintra.Sapra.Model.Facturaajuste;
import caintra.Sapra.Model.MovimientosCaintra;
import caintra.Sapra.Model.Practicante;
import caintra.Sapra.Model.PrefacturaCaintra;
import caintra.Sapra.Model.PrefacturaDetalle;
import caintra.Sapra.Model.PrefacturaDetalleQM;
import caintra.Sapra.Model.PrefacturaQM;
import echopointng.table.DefaultSortableTableModel;
import echopointng.table.SortableTableHeaderRenderer;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import nextapp.echo2.app.Border;
import nextapp.echo2.app.Color;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.Table;
import nextapp.echo2.app.table.DefaultTableModel;

/**
 *
 * @author Administrador
 */
public class TableCaintra extends Table {

    public List<Practicante> lista, lista2;
    public Object[][] arrayObj;
    public Object[] titles;
    private int bandera_negativo = 0;
    private PrefacturaCaintra header;
    private PrefacturaQM headerqm;
    private ArrayList<PrefacturaDetalle> detalle_prefactura;
    private ArrayList<PrefacturaDetalleQM> detalle_prefacturaqm;
    public DecimalFormat formato_decimal = new DecimalFormat("#########.##");
    public double monto_a_pagar, monto_a_pagarqm;
    public double seguro_empresa, seguro_empresaqm, seg_per1, seg_per2;
    public Calendariofacturacionpracticantes fecha,fecha_siguiente;
    public TableCaintra(String action, int size) {
        this.setWidth(new Extent(size));
        this.setDefaultHeaderRenderer(new HeadTableCaintra());

        this.setActionCommand(action);
        this.setSelectionEnabled(true);
        this.setRolloverEnabled(true);
        this.setRolloverForeground(Color.WHITE);
        this.setSelectionBackground(Color.YELLOW);
        this.setRolloverBackground(new Color(186, 240, 240));
        this.setFocusTraversalParticipant(true);
        this.setAutoCreateColumnsFromModel(true);
        this.setBorder(new Border(1, Color.BLACK, Border.STYLE_OUTSET));
        this.setInsets(new Insets(6, 3, 3, 6));
        this.setVisible(true);

    }

    public void putModelo() {
        DefaultTableModel dtm;
        try {
            this.removeAll();
            dtm = new DefaultTableModel(arrayObj, titles);
            this.setModel(dtm);


        } catch (Exception e) {
        }
    }

    public List<Practicante> getLista_Practicante() {
        return lista;
    }

    public void setLista_Practicante(List<Practicante> lista) {
        Practicante p;
        this.setDefaultRenderer(Object.class, new BodyTableCaintra());
        bandera_negativo = 0;
        this.setSelectionEnabled(true);
        this.setRolloverEnabled(true);
        try {
            this.lista = lista;
            titles = new Object[17];
            titles[0] = "#";
            titles[1] = "Cuenta";
            titles[2] = "Pago Neto";
            titles[3] = " Nombre ";
            titles[4] = " Paterno ";
            titles[5] = " Materno ";
            titles[6] = " C. Costo ";
            titles[7] = " Fec. Inicio ";
            titles[8] = " Fec. Termino ";
            titles[9] = " Fec. Cancelacion ";
            titles[10] = " Dias A Pagar ";
            titles[11] = " Monto Beca ";
            titles[12] = " Monto A Pagar ";
            //titles[12]=" Pago Neto ";
            titles[13] = " Seg Emp ";
            titles[14] = " Seg Pract ";
            titles[15] = " Ajuste ";
            titles[16] = " Deduccion ";
            monto_a_pagar = 0.0;
            seguro_empresa = 0.0;
            arrayObj = new Object[lista.size()][17];

            if (lista != null) {

                detalle_prefactura = new ArrayList<PrefacturaDetalle>();
                PrefacturaDetalle d;
                for (int i = 0; i < lista.size(); i++) {
                    p = (Practicante) lista.get(i);
                    monto_a_pagar += p.getMonto_a_pagar();
                    seguro_empresa += p.getSeguroEmpresa();
                    /*if((p.getMonto_a_pagar()- p.getSeguroPracticante()){

                    }*/
                    d=new PrefacturaDetalle();
                    arrayObj[i][0] = i+1;
                    arrayObj[i][1] = p.getCuenta();
                    if (p.getSeguroPracticante() == 0.00) {
                        arrayObj[i][2] = "" + fix_Double(p.getNeto());
                    } else {
                        arrayObj[i][2] = "" + fix_Double(p.getNeto() - p.getSeguroPracticante());
                    }
                    arrayObj[i][3] = p.getNombre();
                    arrayObj[i][4] = p.getPaterno();
                    arrayObj[i][5] = p.getMaterno();
                    arrayObj[i][6] = p.getCentrocosto();
                    arrayObj[i][7] = p.getFecha_Inicio_Str();
                    arrayObj[i][8] = p.getFecha_Termino_Str();
                    if (p.getFec_cancelacion() != null) {
                        arrayObj[i][9] = p.getFecha_Cancelacion_Str();
                    } else {
                        arrayObj[i][9] = "N/D";
                    }

                    arrayObj[i][10] = "" + p.getDias();
                    arrayObj[i][11] = "" + fix_Double(p.getSueldo());
                    arrayObj[i][12] = "" + fix_Double(p.getMonto_a_pagar());
                    //arrayObj[i][12] = ""+fix_Double(p.getNeto());
                    arrayObj[i][13] = "" + fix_Double(p.getSeguroEmpresa());
                    arrayObj[i][14] = "" + fix_Double(p.getSeguroPracticante());
                    arrayObj[i][15] = "" + fix_Double(p.getAjustemonto());
                    arrayObj[i][16] = "" + fix_Double(p.getDeduccionmonto());
                    arrayObj[i][13] = ""+fix_Double(p.getSeguroEmpresa());
                    arrayObj[i][14] = ""+fix_Double(p.getSeguroPracticante());
                    arrayObj[i][15] = ""+fix_Double(p.getAjustemonto());
                    arrayObj[i][16] = ""+fix_Double(p.getDeduccionmonto());

                    if(p.getSeguroPracticante()>0){
                        int aux=0;
                        aux=(int)(p.getNeto()-p.getSeguroPracticante());
                        if( aux >=0){
                            arrayObj[i][2] = ""+fix_Double(aux);
                            d.setNeto(aux);
                        }else{
                            p.setSeguroPracticante(0.0);
                            arrayObj[i][2] = ""+fix_Double(p.getNeto());
                        }
                    }else{
                        d.setNeto(p.getNeto());
                    }
                    if(p.getMonto_a_pagar() < 0 || p.getNeto() < 0){
                        bandera_negativo=1;
                    }
                    d.setNombre(p.getNombre());
                    d.setPaterno(p.getPaterno());
                    d.setMaterno(p.getMaterno());
                    d.setCentrocosto(p.getCentrocosto());
                    d.setFec_inicio(p.getFecha_Inicio_Str());
                    d.setFec_termino(p.getFecha_Termino_Str());

                    if(p.getFec_cancelacion()!=null){
                        d.setFec_baja(p.getFecha_Cancelacion_Str());
                    }else{
                        d.setFec_baja("N/D");
                    }
                    d.setDias_a_pagar(p.getDias());
                    d.setMonto_beca(p.getSueldo());
                    d.setMonto_pagar(p.getMonto_a_pagar());

                    d.setSeg_emp(p.getSeguroEmpresa());
                    d.setSeg_pract(p.getSeguroPracticante());
                    d.setAjuste(p.getAjustemonto());
                    d.setDeduccion(p.getDeduccionmonto());
                    d.setPracticante_Id(p.getPracticanteId());
                    d.setCuenta(p.getCuenta());
                    d.setDepartamento(p.getDepartamento());


                    detalle_prefactura.add(d);


                }

            }
            putModelo();
            this.setDefaultHeaderRenderer(new SortableTableHeaderRenderer());
            DefaultSortableTableModel model = new DefaultSortableTableModel(this.getModel());
            this.setModel(model);
        } catch (Exception e) {
        }
    }

    public void setLista_Practicante_Detalle(List<Practicante> lista) {
        Practicante p;
        try {
            this.setSelectionEnabled(true);
            this.setRolloverEnabled(true);
            this.setDefaultRenderer(Object.class, new BodyDetailTableCaintra());
            this.lista = lista;
            titles = new Object[11];
            titles[0] = " Fec. Inicio ";
            titles[1] = " Fec. Termino ";
            titles[2] = " Fec. Cancelacion ";
            titles[3] = " Dias A Pagar ";
            titles[4] = " Monto Beca ";
            titles[5] = " A Pagar ";
            titles[6] = " Pago Neto ";
            titles[7] = " Seg Emp ";
            titles[8] = " Seg Pract ";
            titles[9] = " Ajuste ";
            titles[10] = " Deduccion ";


            arrayObj = new Object[lista.size()][11];

            if (lista != null) {
                for (int i = 0; i < lista.size(); i++) {
                    p = (Practicante) lista.get(i);
                    arrayObj[i][0] = p.getFecha_Inicio_Str();
                    arrayObj[i][1] = p.getFecha_Termino_Str();
                    arrayObj[i][2] = p.getFecha_Cancelacion_Str();
                    arrayObj[i][3] = "" + p.getDias();
                    arrayObj[i][4] = "" + p.getSueldo();
                    arrayObj[i][5] = "" + p.getMonto_a_pagar();
                    arrayObj[i][6] = "" + p.getNeto();
                    arrayObj[i][7] = "" + p.getSeguroEmpresa();
                    arrayObj[i][8] = "" + p.getSeguroPracticante();
                    arrayObj[i][9] = "" + p.getAjustemonto();
                    arrayObj[i][10] = "" + p.getDeduccionmonto();

                }
            }

            putModelo();
            this.setDefaultHeaderRenderer(new SortableTableHeaderRenderer());
            DefaultSortableTableModel model = new DefaultSortableTableModel(this.getModel());
            this.setModel(model);
        } catch (Exception e) {
        }
    }

    public void setLista_Ajuste(List<Facturaajuste> lista) {
        Facturaajuste f;

        try {
            this.setDefaultRenderer(Object.class, new BodyAjusteTableCaintra());
            //BodyAjusteTableCaintra
            titles = new Object[5];
            titles[0] = " Fecha ";
            titles[1] = " Comentario ";
            //titles[2]=" Tipo Mov";
            titles[2] = " Forma ";
            titles[3] = " Cantidad ";
            titles[4] = " Usuario ";
            arrayObj = new Object[lista.size()][5];
            if (lista != null) {
                for (int i = 0; i < lista.size(); i++) {
                    f = (Facturaajuste) lista.get(i);
                    arrayObj[i][0] = f.fecha_ajuste();
                    arrayObj[i][1] = f.comentario();
                    //arrayObj[i][2] = f.getTipo_Mov();
                    arrayObj[i][2] = f.getForma();
                    arrayObj[i][3] = f.getCantidad();
                    arrayObj[i][4] = f.getLogin();
                }
            }
            putModelo();
        } catch (Exception e) {
        }

    }

    public void setLista_Abono(List<MovimientosCaintra> lista, String usr) {
        MovimientosCaintra ab;

        try {
            this.setDefaultRenderer(Object.class, new BodyAjusteTableCaintra());
            //BodyAjusteTableCaintra
            titles = new Object[4];
            titles[0] = " Monto";
            titles[1] = " Usuario ";
            titles[2] = " Comentarios";
            titles[3] = " Tipo movimiento ";
            arrayObj = new Object[lista.size()][4];
            if (lista != null) {
                for (int i = 0; i < lista.size(); i++) {
                    ab = (MovimientosCaintra) lista.get(i);

                    arrayObj[i][0] = ab.getCantidad();
                    arrayObj[i][1] = usr;
                    arrayObj[i][2] = ab.getComentarios();
                    if (ab.getIsAbono() == 1) {
                        arrayObj[i][3] = "Abono";
                    }
                    if (ab.getIsAbono() == 0) {
                        arrayObj[i][3] = "Adeudo";
                    }
                }
            }
            putModelo();
        } catch (Exception e) {
            System.out.println("Error" + lista.toString());
        }

    }

    public void setLista_Totales(PrefacturaCaintra total) {


        try {
            this.setSelectionEnabled(false);
            this.setRolloverEnabled(false);
            this.setWidth(new Extent(220));


            header = new PrefacturaCaintra();
            this.setDefaultRenderer(Object.class, new TotalTableCaintra());
            //BodyAjusteTableCaintra
            titles = new Object[2];
            titles[0] = " Concepto ";
            titles[1] = " Monto ";
            arrayObj = new Object[12][2];

            arrayObj[0][0] = "Monto A Pagar";
            arrayObj[0][1] = fix_Double(total.getMonto_a_pagar());

            arrayObj[1][0] = total.getPorcentaje() + " % G.Adm.";
            arrayObj[1][1] = fix_Double(total.getGasto_adm());


            arrayObj[2][0] = "SubTotal Sin Seguro";
            arrayObj[2][1] = fix_Double(total.getSubtotal_sin_seguro());

            arrayObj[3][0] = "Seguro Empresa";
            arrayObj[3][1] = fix_Double(total.getSeguro_empresa());

            arrayObj[4][0] = "Adeudos Empresa";
            arrayObj[4][1] = fix_Double(total.getAdeudos_empresa());

            arrayObj[5][0] = "SubTotal Con Seguro";
            arrayObj[5][1] = fix_Double(total.getSubtotal_conseguro());

            arrayObj[6][0] = "I.V.A";
            arrayObj[6][1] = fix_Double(total.getIva_1());

            arrayObj[7][0] = "Total 1";
            arrayObj[7][1] = fix_Double(total.getTotal_1());

            arrayObj[8][0] = "Abono Empresa";
            arrayObj[8][1] = fix_Double(total.getAbono_empresa());

            arrayObj[9][0] = "SubTotal Con Abonos";
            arrayObj[9][1] = fix_Double(total.getSubtotal_con_abono());

            arrayObj[10][0] = "I.V.A";
            arrayObj[10][1] = fix_Double(total.getIva_2());

            arrayObj[11][0] = "Total Final";
            arrayObj[11][1] = fix_Double(total.getTotal_final());
            this.header = total;
            putModelo();
        } catch (Exception e) {
        }

    }

    /////////////////////prefactura quincenal mensual/////////////////////////
    public void setLista_TotalesQM(PrefacturaQM total) {


        try {
            this.setSelectionEnabled(false);
            this.setRolloverEnabled(false);
            this.setWidth(new Extent(220));


            headerqm = new PrefacturaQM();
            this.setDefaultRenderer(Object.class, new TotalTableCaintra());
            //BodyAjusteTableCaintra
            titles = new Object[2];
            titles[0] = " Concepto ";
            titles[1] = " Monto ";
            arrayObj = new Object[12][2];

            arrayObj[0][0] = "Monto A Pagar";
            arrayObj[0][1] = fix_Double(total.getMonto_a_pagar());

            arrayObj[1][0] = total.getPorcentaje() + " % G.Adm.";
            arrayObj[1][1] = fix_Double(total.getGasto_adm());


            arrayObj[2][0] = "SubTotal Sin Seguro";
            arrayObj[2][1] = fix_Double(total.getSubtotal_sin_seguro());

            arrayObj[3][0] = "Seguro Empresa";
            arrayObj[3][1] = fix_Double(total.getSeguro_empresa());

            arrayObj[4][0] = "Adeudos Empresa";
            arrayObj[4][1] = fix_Double(total.getAdeudos_empresa());

            arrayObj[5][0] = "SubTotal Con Seguro";
            arrayObj[5][1] = fix_Double(total.getSubtotal_conseguro());

            arrayObj[6][0] = "I.V.A";
            arrayObj[6][1] = fix_Double(total.getIva_1());

            arrayObj[7][0] = "Total 1";
            arrayObj[7][1] = fix_Double(total.getTotal_1());

            arrayObj[8][0] = "Abono Empresa";
            arrayObj[8][1] = fix_Double(total.getAbono_empresa());

            arrayObj[9][0] = "SubTotal Con Abonos";
            arrayObj[9][1] = fix_Double(total.getSubtotal_con_abono());

            arrayObj[10][0] = "I.V.A";
            arrayObj[10][1] = fix_Double(total.getIva_2());

            arrayObj[11][0] = "Total Final";
            arrayObj[11][1] = fix_Double(total.getTotal_final());
            this.headerqm = total;
            putModelo();
        } catch (Exception e) {
        }

    }

    public void setLista_Total_AutorizadaQM(PrefacturaQM total) {
        try {
            this.setSelectionEnabled(false);
            this.setRolloverEnabled(false);
            this.setWidth(new Extent(220));

            this.setDefaultRenderer(Object.class, new BodyAjusteTableCaintra());
            //BodyAjusteTableCaintra
            titles = new Object[2];
            titles[0] = " Concepto ";
            titles[1] = " Monto ";
            arrayObj = new Object[12][2];

            arrayObj[0][0] = "Monto A Pagar";
            arrayObj[0][1] = total.getMonto_a_pagar();

            arrayObj[1][0] = total.getPorcentaje() + " % G.Adm.";
            arrayObj[1][1] = total.getGasto_adm();


            arrayObj[2][0] = "SubTotal Sin Seguro";
            arrayObj[2][1] = total.getSubtotal_sin_seguro();

            arrayObj[3][0] = "Seguro Empresa";
            arrayObj[3][1] = total.getSeguro_empresa();

            arrayObj[4][0] = "Adeudos Empresa";
            arrayObj[4][1] = total.getAdeudos_empresa();

            arrayObj[5][0] = "SubTotal Con Seguro";
            arrayObj[5][1] = total.getSubtotal_conseguro();

            arrayObj[6][0] = "I.V.A";
            arrayObj[6][1] = total.getIva_1();

            arrayObj[7][0] = "Total 1";
            arrayObj[7][1] = total.getTotal_1();

            arrayObj[8][0] = "Abono Empresa";
            arrayObj[8][1] = total.getAbono_empresa();

            arrayObj[9][0] = "SubTotal Con Abonos";
            arrayObj[9][1] = total.getSubtotal_con_abono();

            arrayObj[10][0] = "I.V.A";
            arrayObj[10][1] = total.getIva_2();

            arrayObj[11][0] = "Total Final";
            arrayObj[11][1] = total.getTotal_final();
            putModelo();
        } catch (Exception e) {
        }
    }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void setLista_Total_Autorizada(PrefacturaCaintra total) {
        try {
            this.setSelectionEnabled(false);
            this.setRolloverEnabled(false);
            this.setWidth(new Extent(220));




            this.setDefaultRenderer(Object.class, new BodyAjusteTableCaintra());
            //BodyAjusteTableCaintra
            titles = new Object[2];
            titles[0] = " Concepto ";
            titles[1] = " Monto ";
            arrayObj = new Object[12][2];

            arrayObj[0][0] = "Monto A Pagar";
            arrayObj[0][1] = total.getMonto_a_pagar();

            arrayObj[1][0] = total.getPorcentaje() + " % G.Adm.";
            arrayObj[1][1] = total.getGasto_adm();


            arrayObj[2][0] = "SubTotal Sin Seguro";
            arrayObj[2][1] = total.getSubtotal_sin_seguro();

            arrayObj[3][0] = "Seguro Empresa";
            arrayObj[3][1] = total.getSeguro_empresa();

            arrayObj[4][0] = "Adeudos Empresa";
            arrayObj[4][1] = total.getAdeudos_empresa();

            arrayObj[5][0] = "SubTotal Con Seguro";
            arrayObj[5][1] = total.getSubtotal_conseguro();

            arrayObj[6][0] = "I.V.A";
            arrayObj[6][1] = total.getIva_1();

            arrayObj[7][0] = "Total 1";
            arrayObj[7][1] = total.getTotal_1();

            arrayObj[8][0] = "Abono Empresa";
            arrayObj[8][1] = total.getAbono_empresa();

            arrayObj[9][0] = "SubTotal Con Abonos";
            arrayObj[9][1] = total.getSubtotal_con_abono();

            arrayObj[10][0] = "I.V.A";
            arrayObj[10][1] = total.getIva_2();

            arrayObj[11][0] = "Total Final";
            arrayObj[11][1] = total.getTotal_final();
            putModelo();
        } catch (Exception e) {
        }
    }

    public void setLista_Pract_Autorizada(List<PrefacturaDetalle> lista) {
        PrefacturaDetalle pd;
        try {
            this.setSelectionEnabled(true);
            this.setRolloverEnabled(true);
            this.setDefaultRenderer(Object.class, new BodyTableCaintra());
            titles = new Object[17];
            titles[0] = "#";
            titles[1] = "Cuenta";
            titles[2] = " Pago Neto";
            titles[3] = " Nombre ";
            titles[4] = " Paterno ";
            titles[5] = " Materno ";
            titles[6] = " C. Costo ";
            titles[7] = " Fec. Inicio ";
            titles[8] = " Fec. Termino ";
            titles[9] = " Fec. Cancelacion ";
            titles[10] = " Dias A Pagar ";
            titles[11] = " Monto Beca ";
            titles[12] = " Monto A Pagar ";

            titles[13] = " Seg Emp ";
            titles[14] = " Seg Pract ";
            titles[15] = " Ajuste ";
            titles[16] = " Deduccion ";
            arrayObj = new Object[lista.size()][17];
            for (int i = 0; i < lista.size(); i++) {
                pd = (PrefacturaDetalle) lista.get(i);
                arrayObj[i][0] = i + 1;
                arrayObj[i][1] = pd.getCuenta();
                arrayObj[i][2] = fix_Double(pd.getNeto());
                arrayObj[i][3] = pd.getNombre();
                arrayObj[i][4] = pd.getPaterno();
                arrayObj[i][5] = pd.getMaterno();

                arrayObj[i][6] = pd.getCentrocosto();
                arrayObj[i][7] = pd.getFec_inicio();
                arrayObj[i][8] = pd.getFec_termino();
                if (pd.getFec_baja() != null) {
                    arrayObj[i][9] = pd.getFec_baja();
                } else {
                    arrayObj[i][9] = "N/D";
                }
                arrayObj[i][10] = pd.getDias_a_pagar();
                arrayObj[i][11] = fix_Double(pd.getMonto_beca());
                arrayObj[i][12] = fix_Double(pd.getMonto_pagar());

                arrayObj[i][13] = fix_Double(pd.getSeg_emp());
                arrayObj[i][14] = fix_Double(pd.getSeg_pract());
                arrayObj[i][15] = fix_Double(pd.getAjuste());
                arrayObj[i][16] = fix_Double(pd.getDeduccion());

            }
            putModelo();
            this.setDefaultHeaderRenderer(new SortableTableHeaderRenderer());
            DefaultSortableTableModel model = new DefaultSortableTableModel(this.getModel());
            this.setModel(model);
        } catch (Exception e) {
        }

    }

    public void setLista_Pract_AutorizadaQM(List<PrefacturaDetalleQM> lista) {
        PrefacturaDetalleQM pd;
        try {
            this.setSelectionEnabled(false);
            this.setRolloverEnabled(false);
            this.setDefaultRenderer(Object.class, new BodyTableCaintra());
            titles = new Object[17];
            titles[0] = "Numero";
            titles[1] = "Cuenta";
            titles[2] = " Nombre ";
            titles[3] = " Paterno ";
            titles[4] = " Materno ";
            titles[5] = " C. Costo ";
            titles[6] = " Fec. Inicio ";
            titles[7] = " Fec. Termino ";
            titles[8]=" Fec. Cancelacion ";
            titles[9] = " Dias A Pagar ";
            titles[10] = " Monto Beca ";
            titles[11] = " Monto A Pagar ";
            titles[12] = " Pago Neto ";
            titles[13] = " Seg Emp ";
            titles[14] = " Seg Pract ";
            titles[15] = " Ajustes ";
            titles[16] = " Deducciones ";
            arrayObj = new Object[lista.size()][17];
            for (int i=0;i < lista.size(); i++){
                if(lista.get(i).getMonto_beca()==0.00){
                    lista.remove(i);
                }

            }

            for (int i = 0; i < lista.size(); i++) {
                pd = (PrefacturaDetalleQM) lista.get(i);
                arrayObj[i][0] = i + 1;
                arrayObj[i][1] = pd.getCuenta();
                arrayObj[i][2] = pd.getNombre();
                arrayObj[i][3] = pd.getPaterno();
                arrayObj[i][4] = pd.getMaterno();
                arrayObj[i][5] = pd.getCentro_costo();
                arrayObj[i][6] = pd.getFec_inicio();
                arrayObj[i][7] = pd.getFec_termino();
                if(pd.getFec_cancelacion()!=null){
                    arrayObj[i][8] = pd.getFec_cancelacion();
                }else{
                    arrayObj[i][8] = "N/D";
                }

                arrayObj[i][9] = pd.getDias_a_pagar();
                arrayObj[i][10] = fix_Double(pd.getMonto_beca());
                arrayObj[i][11] = fix_Double(pd.getMonto_pagar());
                arrayObj[i][12] = fix_Double(pd.getNeto1() + pd.getNeto2());
                arrayObj[i][13] = fix_Double(pd.getSeguro_empresa());
                arrayObj[i][14] = fix_Double(pd.getSeguro_practicante());
                arrayObj[i][15] = fix_Double(pd.getAjustes_1() + pd.getAjustes_2());
                arrayObj[i][16] = fix_Double(pd.getDeducciones_1() + pd.getDeducciones_2());

            }
            putModelo();
            this.setDefaultHeaderRenderer(new SortableTableHeaderRenderer());
            DefaultSortableTableModel model = new DefaultSortableTableModel(this.getModel());
            this.setModel(model);
        } catch (Exception e) {
        }

    }

    public void setBandera_negativo(int bandera_negativo) {
        this.bandera_negativo = bandera_negativo;
    }

    public int getBandera_negativo() {
        return bandera_negativo;
    }

    public ArrayList<PrefacturaDetalle> getDetalle_prefactura() {
        return detalle_prefactura;
    }

    public void setDetalle_prefactura(ArrayList<PrefacturaDetalle> detalle_prefactura) {
        this.detalle_prefactura = detalle_prefactura;
    }

    public ArrayList<PrefacturaDetalleQM> getDetalle_prefacturaQM() {
        return detalle_prefacturaqm;
    }

    public void setDetalle_prefacturaQM(ArrayList<PrefacturaDetalleQM> detalle_prefactura) {
        this.detalle_prefacturaqm = detalle_prefactura;
    }

    public PrefacturaCaintra getHeader() {
        return header;
    }

    public void setHeader(PrefacturaCaintra header) {
        this.header = header;
    }

    public PrefacturaQM getHeaderQM() {
        return headerqm;
    }

    public void setHeaderQM(PrefacturaQM header) {
        this.headerqm = header;
    }

    public double getMonto_a_pagar() {
        return monto_a_pagar;
    }

    public void setMonto_a_pagar(double monto_a_pagar) {
        this.monto_a_pagar = monto_a_pagar;
    }

/////////////////////////////////////////////////////////////////////////////////////////////////
    public double getMonto_a_pagar2() {
        return monto_a_pagarqm;
    }

    public void setMonto_a_pagar2(double monto_a_pagarqm) {
        this.monto_a_pagarqm = monto_a_pagarqm;
    }
///////////////////////////////////////////////////////////////////////////////////////

    public double getSeguro_empresa() {
        return seguro_empresa;
    }

    public void setSeguro_empresa(double seguro_empresa) {
        this.seguro_empresa = seguro_empresa;
    }

    ////////////////////////////////////////////////////////////////////////////////
    public double getSeguro_empresaQM() {
        return seguro_empresaqm;
    }

    public void setSeguro_empresaQM(double seguro_empresa) {
        this.seguro_empresaqm = seguro_empresa;
    }

    public String fix_Double(double doble) {
        String res = "";
        formato_decimal.setMinimumFractionDigits(2);
        formato_decimal.setMaximumFractionDigits(2);
        try {
            res = formato_decimal.format(doble);
            res = "$ " + res;
        } catch (Exception e) {
            return "$ 0,00";
        }
        return res;
    }

    public void setEmpresa_Disponible(List<PrefacturaCaintra> lista, String title) {
        this.setSelectionEnabled(true);
        this.setRolloverEnabled(true);
        this.setDefaultRenderer(Object.class, new DispersionTable());
        PrefacturaCaintra pref;
        try {
            titles = new Object[2];
            titles[0] = title;
            titles[1] = "Neto A Pagar";
            arrayObj = new Object[lista.size()][2];
            for (int i = 0; i < lista.size(); i++) {
                pref = (PrefacturaCaintra) lista.get(i);
                arrayObj[i][0] = pref.getRazon_Empresa();
                arrayObj[i][1] = pref.getNeto_total();
                //arrayObj[i][1] = fix_Double(/*pref.getNeto_total()*/);
            }
            putModelo();

        } catch (Exception e) {
        }



    }

public void setLista_PracticanteQM(List<PrefacturaDetalle> lista_1, List<PrefacturaDetalle> lista_2) {
        PrefacturaDetalleQM p;
       this.setDefaultRenderer(Object.class, new BodyTableCaintra());
       List<PrefacturaDetalleQM> list= new  ArrayList<PrefacturaDetalleQM>();
        bandera_negativo = 0;
        this.setSelectionEnabled(true);
        this.setRolloverEnabled(true);

        try {

         list=establecer_lista(lista_1, lista_2);

            titles = new Object[22];
            titles[0] = "Numero";
            titles[1] = "Cuenta";
            titles[2] = "Nombre";
            titles[3] = "Paterno";
            titles[4] = "Materno";
            titles[5] = "C. Costo";
            titles[6] = "Fec. Inicio";
            titles[7] = "Fec. Termino";
            titles[8] = "Fec. Cancelacion";
            titles[9] = "Dias A Pagar";
            titles[10] = "Monto Beca";
            titles[11] = "Monto a Pagar";
            titles[12] = "A pagar 1";
            titles[13] = "Ajustes 1 ";
            titles[14] = "Deducciones 1";
            titles[15] = "Neto1";
            titles[16] = "A pagar 2 ";
            titles[17] = "Ajustes 2";
            titles[18] = "Deducciones 2";
            titles[19] = "Neto 2";
            titles[20] = "Seguro Empresa";
            titles[21] = "Seguro Practicante";

            monto_a_pagarqm = 0.0;
            //seguro_empresaqm = 0.0;
            double seguro_emp=0.00;

            if(!list.isEmpty()&&list!=null){
                 arrayObj = new Object[list.size()][22];
                 detalle_prefacturaqm = new ArrayList<PrefacturaDetalleQM>();
                 PrefacturaDetalleQM d;

            for (int i = 0; i < list.size(); i++) {
                  p=list.get(i);
                    monto_a_pagarqm += (p.getMonto_pagar());

                     seguro_emp +=p.getSeguro_empresa();


                    d = new PrefacturaDetalleQM();
                    arrayObj[i][0] = i + 1;
                    arrayObj[i][1] = p.getCuenta();
                    arrayObj[i][2] = p.getNombre();
                    arrayObj[i][3] = p.getPaterno();
                    arrayObj[i][4] = p.getMaterno();
                    arrayObj[i][5] = p.getCentro_costo();
                    arrayObj[i][6] = p.getFec_inicio();
                    arrayObj[i][7] = p.getFec_termino();
                    if (p.getFec_cancelacion() != null) {
                        arrayObj[i][8] = p.getFec_cancelacion();
                    } else {
                        arrayObj[i][8] = "N/D";
                    }
                    arrayObj[i][9] = "" + p.getDias_a_pagar();
                    arrayObj[i][10] = "" + fix_Double(p.getMonto_beca());
                    arrayObj[i][11] = "" + fix_Double(p.getMonto_pagar());
                    arrayObj[i][12] = "" + fix_Double(p.getPagar_1());
                    arrayObj[i][13] = "" + fix_Double(p.getAjustes_1());
                    arrayObj[i][14] = "" + fix_Double(p.getDeducciones_1());
                    arrayObj[i][15] = "" + fix_Double(p.getNeto1());
                    arrayObj[i][16] = "" + fix_Double(p.getPagar_2());
                    arrayObj[i][17] = "" + fix_Double(p.getAjustes_2());
                    arrayObj[i][18] = "" + fix_Double(p.getDeducciones_2());
                    arrayObj[i][19] = "" + fix_Double(p.getNeto2());
                    arrayObj[i][20] = "" + fix_Double(p.getSeguro_empresa());
                    arrayObj[i][21] = "" + fix_Double(p.getSeguro_practicante());

                    if (p.getMonto_pagar() < 0) {
                        bandera_negativo = 1;
                    }

                    d.setNombre(p.getNombre());
                    d.setPaterno(p.getPaterno());
                    d.setMaterno(p.getMaterno());
                    d.setCentro_costo(p.getCentro_costo());
                    d.setFec_inicio(p.getFec_inicio());
                    d.setFec_termino(p.getFec_termino());
                    d.setDias_a_pagar(p.getDias_a_pagar());
                    d.setMonto_beca(p.getMonto_beca());
                    d.setMonto_pagar(p.getMonto_pagar());
                    d.setPagar_1(p.getPagar_1());
                    d.setPagar_2(p.getPagar_2());
                    d.setAjustes_1(p.getAjustes_1());
                    d.setAjustes_2(p.getAjustes_2());
                    d.setDeducciones_1(p.getDeducciones_1());
                    d.setDeducciones_2(p.getDeducciones_2());
                    d.setSeguro_empresa(p.getSeguro_empresa());
                    d.setSeguro_practicante(p.getSeguro_practicante());
                    d.setPracticanteId(p.getPracticanteId());
                    d.setCuenta(p.getCuenta());
                    d.setNeto1(p.getNeto1());
                    d.setNeto2(p.getNeto2());

                    seguro_empresaqm=seguro_emp;

                    detalle_prefacturaqm.add(d);


                }
            }
            putModelo();
            this.setDefaultHeaderRenderer(new SortableTableHeaderRenderer());
            DefaultSortableTableModel model = new DefaultSortableTableModel(this.getModel());
            this.setModel(model);
        } catch (Exception e) {
            System.out.println("Error" + e.getMessage());
        }
    }


    public void setLista_Pract_Dispersion(List<PrefacturaDetalle> lista) {

        PrefacturaDetalle pd;
        try {
            this.setSelectionEnabled(true);
            this.setRolloverEnabled(true);
            this.setWidth(new Extent(400));


            header = new PrefacturaCaintra();
            this.setDefaultRenderer(Object.class, new CuentaCaintra());
            //BodyAjusteTableCaintra
            titles = new Object[5];
            titles[0] = "#";
            titles[1] = "Numero";
            titles[2] = "Cuenta";
            titles[3] = " Neto ";
            arrayObj = new Object[lista.size()][4];
            for (int i = 0; i < lista.size(); i++) {
                pd = (PrefacturaDetalle) lista.get(i);
                arrayObj[i][0] = "" + (i + 1);
                arrayObj[i][1] = "" + pd.getNombre() + " " + pd.getPaterno() + " " + pd.getMaterno();
                arrayObj[i][2] = "" + pd.getCuenta();
                arrayObj[i][3] = "" + fix_Double(pd.getNeto());
            }

            putModelo();
        } catch (Exception e) {
        }

    }

    public void setCalendario(ArrayList<Calendariofacturacionpracticantes> lista) {
        Calendariofacturacionpracticantes cf;
        try {
            this.setSelectionEnabled(true);
            this.setRolloverEnabled(true);
            this.setDefaultRenderer(Object.class, new CuentaCaintra());
            titles = new Object[8];
            titles[0] = "#";
            titles[1] = " Limite Autorizacion ";
            titles[2] = " GAP ";
            titles[3] = " Dispersion ";
            titles[4] = " Pago ";
            titles[5] = " Inicio ";
            titles[6] = " Fin ";
            titles[7] = " Dias ";

            arrayObj = new Object[lista.size()][8];
            for (int i = 0; i < lista.size(); i++) {
                cf = (Calendariofacturacionpracticantes) lista.get(i);
                arrayObj[i][0] = "" + (i + 1);
                arrayObj[i][1] = "" + cf.getDia_Limite_Str();
                arrayObj[i][2] = "" + cf.getDia_Gap_Str();
                arrayObj[i][3] = "" + cf.getDia_Dispersion_Str();
                arrayObj[i][4] = "" + cf.getDia_Pago_Str();
                arrayObj[i][5] = "" + cf.getDia_Inicio_Str();
                arrayObj[i][6] = "" + cf.getDia_Fin_Str();
                arrayObj[i][7] = "" + cf.getDias_a_pagar_periodo();
            }
            putModelo();
        } catch (Exception e) {
        }

    }

    public void setCalendario(List<Calendariofacturacionpracticantes> lista) {
        Calendariofacturacionpracticantes cf;
        try {
            this.setSelectionEnabled(true);
            this.setRolloverEnabled(true);
            this.setDefaultRenderer(Object.class, new CuentaCaintra());
            titles = new Object[8];
            titles[0] = "#";
            titles[1] = " Limite Autorizacion ";
            titles[2] = " GAP ";
            titles[3] = " Dispersion ";
            titles[4] = " Pago ";
            titles[5] = " Inicio ";
            titles[6] = " Fin ";
            titles[7] = " Dias ";

            arrayObj = new Object[lista.size()][8];
            for (int i = 0; i < lista.size(); i++) {
                cf = (Calendariofacturacionpracticantes) lista.get(i);
                arrayObj[i][0] = "" + (i + 1);
                arrayObj[i][1] = "" + cf.getDia_Limite_Str();
                arrayObj[i][2] = "" + cf.getDia_Gap_Str();
                arrayObj[i][3] = "" + cf.getDia_Dispersion_Str();
                arrayObj[i][4] = "" + cf.getDia_Pago_Str();
                arrayObj[i][5] = "" + cf.getDia_Inicio_Str();
                arrayObj[i][6] = "" + cf.getDia_Fin_Str();
                arrayObj[i][7] = "" + cf.getDias_a_pagar_periodo();
            }
            putModelo();
        } catch (Exception e) {
        }

    }

    public PrefacturaDetalle setPracticanteRelleno() {
        PrefacturaDetalle pr = new PrefacturaDetalle();
        pr.setCuenta(null);
        pr.setNombre(" ");
        pr.setPaterno(" ");
        pr.setMaterno(" ");
        pr.setCentrocosto(" ");
        pr.setFec_inicio(null);
        pr.setFec_termino(null);
        pr.setFec_baja(null);
        pr.setDias_a_pagar(0);
        pr.setMonto_beca(0.00);
        pr.setMonto_pagar(0.00);
        pr.setAjuste(0.00);
        pr.setDeduccion(0.00);
        pr.setNeto(0.00);
        pr.setSeg_emp(0.00);
        pr.setSeg_pract(0.00);

        return pr;
    }

 
    

      public List<PrefacturaDetalle> reestablecer_lista(List<PrefacturaDetalle> li1) {
        List<PrefacturaDetalle> l_total = new ArrayList<PrefacturaDetalle>();
        double valor=0.00;

        try {
            for (int i = 0; i < li1.size(); i++) {
                valor= li1.get(i).getMonto_beca();
                if(valor==0){
                    li1.remove(i);
                }


            }
            l_total=li1;


        } catch (Exception e) {
        }
        Collections.sort(l_total);

        return l_total;
    }

            public List<PrefacturaDetalleQM> reestablecer_lista2(List<PrefacturaDetalleQM> li1) {
        List<PrefacturaDetalleQM> l_total = new ArrayList<PrefacturaDetalleQM>();
        double valor=0.00;

        try {
            for (int i = 0; i < li1.size(); i++) {
                valor= li1.get(i).getMonto_beca();
                if(valor==0){
                    li1.remove(i);
                }


            }
            l_total=li1;


        } catch (Exception e) {
        }
        //Collections.sort(l_total);

        return l_total;
    }

     public List<PrefacturaDetalleQM> establecer_lista(List<PrefacturaDetalle> li1, List<PrefacturaDetalle> li2) {
        List<PrefacturaDetalleQM> l_total = new ArrayList<PrefacturaDetalleQM>();
        PrefacturaDetalle p1 =new PrefacturaDetalle();
        PrefacturaDetalle p2 =new PrefacturaDetalle();
        PrefacturaDetalleQM pt =new PrefacturaDetalleQM();
        PrefacturaDetalleQM p_1, p_2;

        int ciclo=0;
        if(li1.size()>li2.size()){
            ciclo=li1.size();
        }
        if(li2.size()>li1.size()){
            ciclo=li2.size();
        }
        if(li1.size()==li2.size()){
            ciclo=li1.size();
        }

        for(int i=0; i<ciclo; i++){
              try{
                  li1.get(i);
              }catch(Exception ex){
                  li1.add(i, setPracticanteRelleno());
              }

              try{
                  li2.get(i);
              }catch(Exception ex){
                  li2.add(i, setPracticanteRelleno());
              }

            if(li1.get(i).getNombre().equals(li2.get(i).getNombre())&& li1.get(i).getPaterno().equals(li2.get(i).getPaterno())
                    && li1.get(i).getMaterno().equals(li2.get(i).getMaterno())){

            }else if(li1.size()<li2.size()){
                li1.add(i,setPracticanteRelleno());

            }
            else if(li2.size()<li1.size()){
                li2.add(i,setPracticanteRelleno());

            }
            else if(li2.size()==li1.size()){
                if(!(li1.get(i).getNombre().trim().equals(""))&& !(li2.get(i).getNombre().trim().equals(""))){
                    li2.add(i,setPracticanteRelleno());
                }
                if(li1.get(i).getNombre().trim().equals("")){

                }
                if(li2.get(i).getNombre().trim().equals("")){

                }
                
                //li1.add(i, setPracticanteRelleno());
                ciclo=ciclo+1;

            }

        }

        for(int i=0;i<li1.size();i++){
            p1=li1.get(i);
            p2=li2.get(i);

            if(p1.getNombre().trim().equals("")&&p2.getNombre().trim().equals("")){
                li1.remove(i);
                li2.remove(i);
            }else{

                if(p1.getNombre().trim().equals("")){
                       p_2=new PrefacturaDetalleQM();
                       p_2.setNombre(p2.getNombre());
                       p_2.setPaterno(p2.getPaterno());
                       p_2.setMaterno(p2.getMaterno());
                       p_2.setCentro_costo(p2.getCentrocosto());
                       p_2.setMonto_beca(p2.getMonto_beca());
                       p_2.setDias_a_pagar(p2.getDias_a_pagar());
                       p_2.setAjustes_1(0.00);
                       p_2.setAjustes_2(p2.getAjuste());
                       p_2.setDeducciones_1(0.00);
                       p_2.setDeducciones_2(p2.getDeduccion());
                       p_2.setPagar_1(0.00);
                       p_2.setPagar_2(p2.getMonto_pagar());
                       p_2.setNeto1(0.00);
                       p_2.setNeto2(p2.getNeto());
                       p_2.setMonto_pagar(p2.getMonto_pagar());
                       p_2.setFec_inicio(p2.getFec_inicio());
                       p_2.setFec_termino(p2.getFec_termino());
                       p_2.setFec_cancelacion(p2.getFec_baja());
                       p_2.setPracticanteId(p2.getPracticante_Id());
                       p_2.setCuenta(p2.getCuenta());
                       p_2.setSeguro_empresa(p2.getSeg_emp());
                       p_2.setSeguro_practicante(p2.getSeg_pract());
                      l_total.add(p_2);

                }

                if(p2.getNombre().trim().equals("")){
                    p_1=new PrefacturaDetalleQM();
                     p_1.setNombre(p1.getNombre());
                       p_1.setPaterno(p1.getPaterno());
                       p_1.setMaterno(p1.getMaterno());
                       p_1.setCentro_costo(p1.getCentrocosto());
                       p_1.setMonto_beca(p1.getMonto_beca());
                       p_1.setDias_a_pagar(p1.getDias_a_pagar());
                       p_1.setAjustes_1(p1.getAjuste());
                       p_1.setAjustes_2(0.00);
                       p_1.setDeducciones_1(p1.getDeduccion());
                       p_1.setDeducciones_2(0.00);
                       p_1.setPagar_1(p1.getMonto_pagar());
                       p_1.setPagar_2(0.00);
                       p_1.setNeto1(p1.getNeto());
                       p_1.setNeto2(0.00);
                       p_1.setMonto_pagar(p1.getMonto_pagar());
                       p_1.setFec_inicio(p1.getFec_inicio());
                       p_1.setFec_termino(p1.getFec_termino());
                       p_1.setFec_cancelacion(p1.getFec_baja());
                       p_1.setPracticanteId(p1.getPracticante_Id());
                       p_1.setCuenta(p1.getCuenta());
                       p_1.setSeguro_empresa(p1.getSeg_emp());
                       p_1.setSeguro_practicante(p1.getSeg_pract());
               l_total.add(p_1);
               }else if(!(p1.getNombre().trim().equals("")) && !(p2.getNombre().trim().equals(""))){
                    pt=new PrefacturaDetalleQM();
                       pt.setNombre(p1.getNombre());
                       pt.setPaterno(p1.getPaterno());
                       pt.setMaterno(p1.getMaterno());
                       pt.setCentro_costo(p1.getCentrocosto());
                       pt.setMonto_beca(p1.getMonto_beca());
                       pt.setDias_a_pagar(p1.getDias_a_pagar()+p2.getDias_a_pagar());
                       pt.setAjustes_1(p1.getAjuste());
                       pt.setAjustes_2(p2.getAjuste());
                       pt.setDeducciones_1(p1.getDeduccion());
                       pt.setDeducciones_2(p2.getDeduccion());
                       pt.setPagar_1(p1.getMonto_pagar());
                       pt.setPagar_2(p2.getMonto_pagar());
                       pt.setNeto1(p1.getNeto());
                       pt.setNeto2(p2.getNeto());
                       pt.setMonto_pagar(p1.getMonto_pagar()+p2.getMonto_pagar());

                   if(p1.getPracticante_Id()>p2.getPracticante_Id()){
                                       pt.setFec_inicio(p1.getFec_inicio());
                                       pt.setFec_termino(p1.getFec_termino());
                                       pt.setFec_cancelacion(p1.getFec_baja());
                                       pt.setPracticanteId(p1.getPracticante_Id());
                                       pt.setCuenta(p1.getCuenta());

                        }
                       if(p2.getPracticante_Id()>p1.getPracticante_Id()){
                            pt.setFec_inicio(p2.getFec_inicio());
                            pt.setFec_termino(p2.getFec_termino());
                            pt.setFec_cancelacion(p2.getFec_baja());
                            pt.setPracticanteId(p2.getPracticante_Id());
                            pt.setCuenta(p2.getCuenta());
                        }
                       if(p2.getPracticante_Id()==p1.getPracticante_Id()){
                            pt.setFec_inicio(p1.getFec_inicio());
                            pt.setFec_termino(p1.getFec_termino());
                            pt.setFec_cancelacion(p1.getFec_baja());
                            pt.setPracticanteId(p1.getPracticante_Id());
                            pt.setCuenta(p1.getCuenta());
                        }

                       if(p1.getSeg_emp()!=0){
                           pt.setSeguro_empresa(p1.getSeg_emp());
                       }
                       if(p1.getSeg_pract()!=0){
                           pt.setSeguro_practicante(p1.getSeg_pract());
                       }
                       if(p2.getSeg_emp()!=0){
                           pt.setSeguro_empresa(p2.getSeg_emp());
                       }
                       if(p2.getSeg_pract()!=0){
                           pt.setSeguro_practicante(p2.getSeg_pract());
                       }

                l_total.add(pt);

               }

            }

        }

        return l_total;
    }

    public Calendariofacturacionpracticantes getFecha() {
        return fecha;
    }

    public void setFecha(Calendariofacturacionpracticantes fecha) {
        this.fecha = fecha;
    }

    public Calendariofacturacionpracticantes getFecha_siguiente() {
        return fecha_siguiente;
    }

    public void setFecha_siguiente(Calendariofacturacionpracticantes fecha_siguiente) {
        this.fecha_siguiente = fecha_siguiente;
    }



}